<?php 
Load::models('proveedor');
class ProveedorController extends AppController 
{
    public function before_filter() {
        if ( !Auth::is_valid()){
            Router::redirect('usuario/login/');
        }else{
            $this->tipoMenu="proveedor";
        }
    }
    
    public function index()
    {
        
    }
     public function agregar()
    {
        if(Input::hasPost('proveedor')){
           
            $proveedor = new Proveedor(Input::post('proveedor'));
            
             if(!$proveedor->save()){
                Flash::error('Falló Operación');
                
                $this->proveedor = $this->post('proveedor');
              
            }else{
                Flash::success('Operación exitosa');
            }
        }
    }
    public function eliminar($id){
       $proveedor = new Proveedor();
       $proveedor = $proveedor->find($id);
       $proveedor->estado = "0";
            
       if ($proveedor->update()) {
            Flash::valid('Operación exitosa');
       }else{
           Flash::error('Falló Operación'); 
       }
        return Router::redirect('proveedor/listar');
    }
    
    public function listar(){
         $proveedor = new Proveedor();
         $this->proveedor =   $proveedor->find("order: nombre","conditions: estado=1");
    }
    
    public function verPDF(){
        
    }
    
    public function verXLS(){
        
    }
    
    
}
?>
